Post

Replies

Boosts

Views

Activity

Remaining page rect after UIViewPrintFormatter added to UIPrintPageRenderer
I'm using an instance of a UIPrintPageRenderer subclass to print many records, each of which is included by adding a UIViewPrintFormatter generated by a myTextView.viewPrintFormatter(). Some of the records occupy much less than a page, so I'd like to print the next record on the remaining page space after printing the previous one (only if there is enough space for the entire of the next record on that same page). In order to do this, I'm attempting to calculate how much space is remaining, and where on the page it starts as follows: class MyCustomPrintPageRenderer: UIPrintPageRenderer { func inWhichPrintFormattersAreAdded() { var startPage: Int = 0 for rec in records { let myUIViewPrintFormatter = myTextView.viewPrintFormatter() if enoughSpaceRemainingOnPage() { myUIViewPrintFormatter.perPageContentInsets.top = prevRecBottom } else { startPage += 1 } addPrintFormatter(myUIViewPrintFormatter, startingAtPageAt: startPage) ... ... ... let lastPage = startPage + myUIViewPrintFormatter.pageCount - 1 let lastRect = myUIViewPrintFormatter.rectForPage(at: lastPage) print(lastRect) print(printableRect) ... ... ... startPage = lastPage prevRecBottom = lastRect.origin.y + lastRect.size.height } } } However, the two print() statements always result in exactly the same output - the entire page printable rect. I can't just use the print formatter's total size, as some of them are large enough to occupy multiple pages. I just need to figure out how much space is left on the last page, to see if the next print formatter might fit there. How can I find the used and/or remaining space left on the last page after a UIViewPrintFormatter has been added to a UIPrintPageRenderer ?
0
0
375
Aug ’22
Remaining page rect after UIViewPrintFormatter added to UIPrintPageRenderer
I'm using an instance of a UIPrintPageRenderer subclass to print many records, each of which is included by adding a UIViewPrintFormatter generated by a myTextView.viewPrintFormatter(). Some of the records occupy much less than a page, so I'd like to print the next record on the remaining page space after printing the previous one (only if there is enough space for the entire of the next record on that same page). In order to do this, I'm attempting to calculate how much space is remaining, and where on the page it starts as follows: class MyCustomPrintPageRenderer: UIPrintPageRenderer { func inWhichPrintFormattersAreAdded() { var startPage: Int = 0 for rec in records { let myUIViewPrintFormatter = myTextView.viewPrintFormatter() if enoughSpaceRemainingOnPage() { myUIViewPrintFormatter.perPageContentInsets.top = prevRecBottom } else { startPage += 1 } addPrintFormatter(myUIViewPrintFormatter, startingAtPageAt: startPage) ... ... ... let lastPage = startPage + myUIViewPrintFormatter.pageCount - 1 let lastRect = myUIViewPrintFormatter.rectForPage(at: lastPage) print(lastRect) print(printableRect) ... ... ... startPage = lastPage prevRecBottom = lastRect.origin.y + lastRect.size.height } } } However, the two print() statements always result in exactly the same output - the entire page printable rect. I can't just use the print formatter's total size, as some of them are large enough to occupy multiple pages. I just need to figure out how much space is left on the last page, to see if the next print formatter might fit there. How can I find the used and/or remaining space left on the last page after a UIViewPrintFormatter has been added to a UIPrintPageRenderer ?
1
0
393
Jul ’22